package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PositionStudent;
import com.ruoyi.system.service.IPositionStudentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import java.io.IOException;

/**
 * 警校考生职位选择信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/system/position")
public class PositionStudentController extends BaseController
{
    @Autowired
    private IPositionStudentService positionStudentService;

    /**
     * 查询警校考生职位选择信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:list')")
    @GetMapping("/list")
    public TableDataInfo list(PositionStudent positionStudent)
    {
        startPage();
        List<PositionStudent> list = positionStudentService.selectPositionStudentList(positionStudent);
        return getDataTable(list);
    }

    /**
     * 导出警校考生职位选择信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:position:export')")
    @Log(title = "警校考生职位选择信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PositionStudent positionStudent)
    {
        List<PositionStudent> list = positionStudentService.selectPositionStudentList(positionStudent);
        ExcelUtil<PositionStudent> util = new ExcelUtil<PositionStudent>(PositionStudent.class);
        util.exportExcel(response, list, "警校考生职位选择信息数据");
    }

    /**
     * 导入警校考生职位选择信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:import')")
    @Log(title = "警校考生职位选择信息", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<PositionStudent> util = new ExcelUtil<PositionStudent>(PositionStudent.class);
        List<PositionStudent> positionStudentList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = positionStudentService.importPositionStudent(positionStudentList, updateSupport, operName);
        return success(message);
    }

    /**
     * 获取导入模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<PositionStudent> util = new ExcelUtil<PositionStudent>(PositionStudent.class);
        util.importTemplateExcel(response, "警校考生职位选择信息");
    }

    /**
     * 获取警校考生职位选择信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(positionStudentService.selectPositionStudentById(id));
    }

    /**
     * 新增警校考生职位选择信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:add')")
    @Log(title = "警校考生职位选择信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PositionStudent positionStudent)
    {
        return toAjax(positionStudentService.insertPositionStudent(positionStudent));
    }

    /**
     * 修改警校考生职位选择信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:edit')")
    @Log(title = "警校考生职位选择信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PositionStudent positionStudent)
    {
        return toAjax(positionStudentService.updatePositionStudent(positionStudent));
    }

    /**
     * 删除警校考生职位选择信息
     */
    @PreAuthorize("@ss.hasPermi('system:position:remove')")
    @Log(title = "警校考生职位选择信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(positionStudentService.deletePositionStudentByIds(ids));
    }
}
